<!--
 The BSD 3-Clause License

 Copyright 2022 - DATATRONiQ GmbH (https://datatroniq.com)
 Copyright (c) 2018-2022 Klaus Landsdorf (http://node-red.plus/)
 All rights reserved.
 node-red-contrib-iiot-opcua
-->

<script type="text/javascript">
  RED.nodes.registerType('OPCUA-IIoT-Flex-Connector', {
    category: 'IIoT',
    color: '#ABCDEF',
    defaults: {
      name: {value: ''},
      showStatusActivities: {value: false},
      showErrors: {value: false},
      connector: {type: 'OPCUA-IIoT-Connector', required: true}
    },
    inputs: 1,
    outputs: 1,
    align: 'left',
    icon: 'icon.png',
    label: function () {
      return this.name || 'Flex Connector'
    },
    labelStyle: function () {
      return this.name ? 'node_label_italic' : ''
    },
    oneditprepare: function () {
      let node = this
    }
  })
</script>

<script type="text/x-red" data-template-name="OPCUA-IIoT-Flex-Connector">
    <div class="form-row">
        <label for="node-input-connector"><i class="icon-globe"></i> <span data-i18n="opcua-iiot-contrib.label.connector"></span></label>
        <input type="text" id="node-input-connector" placeholder="opc.tcp://localhost:4334">
    </div>
    <div class="form-row">
        <label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="node-red:common.label.name"></span></label>
        <input type="text" id="node-input-name" placeholder="">
    </div>
    <hr>
    <div class="form-row">
        <label style="min-width:160px" for="node-input-showStatusActivities"><i class="fa fa-bolt"></i>
        <span data-i18n="opcua-iiot-contrib.label.showActivities"></span></label>
        <input type="checkbox" id="node-input-showStatusActivities" style="max-width:30px">
    </div>
    <div class="form-row">
        <label style="min-width:160px" for="node-input-showErrors"><i class="fa fa-exclamation-circle"></i>
        <span data-i18n="opcua-iiot-contrib.label.showErrors"></span></label>
        <input type="checkbox" id="node-input-showErrors" style="max-width:30px">
    </div>
</script>

<script type="text/x-red" data-help-name="OPCUA-IIoT-Flex-Connector">
    <h2>OPC UA IIoT Flex Connector</h2>

    <p>
        The Flex Connector node is to set up an event listener with parameters
        to change the linked connector settings and restart the connection.
        It is to trigger by an Inject of Node-RED or by the IIoT OPC UA Inject.
        It could also get a trigger with incoming events from other nodes.
    </p>

    <h3>Input</h3>

    <p>The node takes the parameters from the msg object or from the node setting as default.
    That means - an empty msg object will just reset the connection and is like a command to just restart the connector with the node parameters.</p>

    <p>msg with connector parameters</p>

    <ul>
        <li>endpoint (string with opc.tcp://)
        <li>keepSessionAlive (boolean)
        <li>securityPolicy (string)
        <li>securityMode (string)
        <li>name (string)
        <li>showErrors (boolean)
        <li>publicCertificateFile (path string)
        <li>privateKeyFile (path string)
        <li>defaultSecureTokenLifetime (number)
        <li>endpointMustExist (boolean)
        <li>autoSelectRightEndpoint (boolean)
        <li>strategyMaxRetry (number)
        <li>strategyInitialDelay (number)
        <li>strategyMaxDelay (number)
        <li>strategyRandomisationFactor (float from 0 .. 1)
        <li>requestedSessionTimeout (number)
        <li>connectionStartDelay (number)
        <li>reconnectDelay (number)
    </ul>

    <h3>Output</h3>

    <p>A msg object with connector parameters and a result if the restart with new settings was done.</p>

    <strong>Name</strong>
    <p>Name in the flow of Node-RED.</p>

</script>
